package org.example.demoarticle.Mapper;


import org.apache.ibatis.annotations.*;
import org.example.demoarticle.pojo.Article;
import org.example.demoarticle.pojo.ArticleInsert;
import org.example.demoarticle.pojo.Student;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;


@Mapper
public interface ArticleMapper {

    List<Article> tchList(String username, String usertype, String className, String creator, String category, String stem, LocalDate fromDate, LocalDate toDate);

    List<Article> stuList(String username,String usertype,String className,String creator,String category,String stem,LocalDate fromDate,LocalDate toDate);

    @Delete("delete from article where id=#{id}")
    void deleteById(Integer id);

    @Select("select * from student where id=" +
            "(select category_id from article where id=#{id})")
    Student selectByArticleId(Integer id);

    @Update("update student set article_num = #{articleNum-1}")
    void updateArticleNum(Student student);

    @Insert("insert into article (stem,content,category_id,created_id) values (#{stem},#{content},#{categoryId},#{username})")
    void Insert(ArticleInsert article);

    @Update("update article set created_id=#{username},stem=#{stem},content=#{content},category_id=#{categoryId} where id=#{id}")
    void Update(Integer id, ArticleInsert article);

    @Select("select stem,content,created_id,createdAt,student.name studentName,class.name className,category_id" +
            "from student,article,class where article.id=#{id} and student.id=article.created_id and class.id=student.class_id")
    Article Select(Integer id);
}

